<?php

namespace app\model;

use think\model\concern\SoftDelete;

/**
 *角色表
 */
class AdminRolesModel extends BaseModel
{

    use SoftDelete;
    
    protected $name = 'admin_roles';

    
    public static function getList($params = []){

        $limit = $params['limit'] ?? 15;

        $list = self::where(function($query) use ($params){

        })->order("id asc")->paginate($limit);

        return $list;
    }

    //获取某个管理员的菜单/权限
    public static function getAdminMenu($adminid){

        $roles = AdminModel::where("id",$adminid)->value("roles");

        //查询所有角色菜单
        $roles_menu_ids = AdminRolesModel::field("menu_ids")->where("id",'in',$roles)->select();

        if(empty($roles_menu_ids)){
            return success("ok",[]);
        }

        $menu_ids = [];
        foreach($roles_menu_ids as $k=>$v){
            $menu_ids = array_merge($menu_ids, explode(",", $v['menu_ids']));
        }

        $menu_ids = array_filter(array_unique($menu_ids));

        return $menu_ids;
    }

}